<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateNotificationLogsTable extends Migration
{
    public function up()
    {
        Schema::create('notification_logs', function (Blueprint $table) {
            $table->bigIncrements('id')->comment('ID');
            $table->string('notification_type', 50)->comment('通知类型：sign_in-签到提醒 duty_leader-当班班长 duty_supervisor-值班领导');
            $table->unsignedBigInteger('recipient_id')->comment('接收人ID');
            $table->string('recipient_name')->comment('接收人姓名');
            $table->unsignedBigInteger('related_id')->nullable()->comment('关联记录ID');
            $table->date('related_date')->nullable()->comment('关联日期');
            $table->text('message_content')->nullable()->comment('消息内容');
            $table->string('send_status', 20)->default('pending')->comment('发送状态：pending-待发送 success-成功 failed-失败');
            $table->text('send_result')->nullable()->comment('发送结果');
            $table->datetime('sent_at')->nullable()->comment('发送时间');

            $table->timestamps();

            $table->index('notification_type', 'idx_notification_type')->comment('通知类型索引');
            $table->index('recipient_id', 'idx_recipient_id')->comment('接收人ID索引');
            $table->index('related_date', 'idx_related_date')->comment('关联日期索引');
            $table->index('send_status', 'idx_send_status')->comment('发送状态索引');
        });

        DB::statement('alter table' . ' ' . config('database.connections.mysql.prefix', '') . 'feedbacks comment "系统通知记录表"');

    }

    public function down()
    {
        Schema::dropIfExists('notification_logs');
    }
}

